//
//  TSellThingsListViewController.m
//  LoveShare
//
//  Created by ways on 2017/4/28.
//  Copyright © 2017年 tikeyc. All rights reserved.
//

#import "TSellThingsListViewController.h"

#import "TReleaseSellThingsViewController.h"
#import "TSellThingsListTableView.h"

@interface TSellThingsListViewController ()

@property (strong, nonatomic) IBOutlet TSellThingsListTableView *tableView;
@property (strong, nonatomic) IBOutlet UIButton *releaseButton;


@end

@implementation TSellThingsListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self initProperty];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark - init

- (void)initProperty {
    
    if (_isReleaseShoppingComing) {
        self.title = @"买东西发布记录";
        [self.releaseButton setTitle:@"我要买东西" forState:UIControlStateNormal];
    } else self.title = @"卖东西";
    
    @weakify(self)
    [[self.releaseButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        if (self.isReleaseShoppingComing) {
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            TReleaseSellThingsViewController *sellThingsVC = [[TReleaseSellThingsViewController alloc] init];
            [self.navigationController pushViewController:sellThingsVC animated:YES];
        }
        
    }];
    
    [self initMJRefresh];
}

- (void)initMJRefresh {
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //Call this Block When enter the refresh status automatically
        [self loadNewData];
    }];
    // Enter the refresh status immediately
    [self.tableView.mj_header beginRefreshing];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //Call this Block When enter the refresh status automatically
        [self loadMoreData];
    }];
}


#pragma mark -

- (void)loadNewData {
    [self.tableView.mj_header performSelector:@selector(endRefreshing) withObject:nil afterDelay:1.0];
}

- (void)loadMoreData {
    [self.tableView.mj_footer performSelector:@selector(endRefreshing) withObject:nil afterDelay:1.0];
}

@end
